{include file='news/header'}
<div class="container">
    <h1 class="page-header"><a href="./list">TP应用示例</a></h1>
    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-warning">
                <div class="panel-heading">
                  <h2 class="text-center">编辑新闻</h2>
                </div>
                <div class="panel-body">
                    <div class="form-horizontal">
                        <div class="form-group">
                            <label for="title" class="col-sm-2 control-label">标题</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" value="{$info['title']}" id="title" placeholder="新闻标题">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="description" class="col-sm-2 control-label">标签</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" value="{$info['label']}" id="label" placeholder="新闻标签">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="description" class="col-sm-2 control-label">简介</label>
                            <div class="col-sm-10">
                                <textarea class="form-control" rows="4" id="description" placeholder="新闻简介">{$info['description']}</textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="content" class="col-sm-2 control-label">内容</label>
                            <div class="col-sm-10">
                                <textarea class="form-control" rows="12" id="content" placeholder="新闻内容">{$info['content']}</textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                {if !empty($info['id'])}<input type="hidden" name="id" id="id" value="{$info['id']}">{/if}
                                <button class="btn btn-default" onclick="saveData()">保存</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    function saveData(){
        var url ='./save';
        var id = $('#id').val();
        var title = $('#title').val();
        var label = $('#label').val();
        var description = $('#description').val();
        var content = $('#content').val();
        $.post(url, {id:id,title:title,label:label,description:description,content:content}, function(data) {
            if (0 == data.code) {
                alert(data.message)
                window.location.href = './list';
            }
        });
    }
</script>
</body>
</html>